<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script language="javascript">
        //打印代码
        function Print() {
            var printStr = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body >";
            var content = "";

            var str = document.getElementById('page1').innerHTML;     //获取需要打印的页面元素 ，page1元素设置样式page-break-after:always，意思是从下一行开始分割。
            content = content + str;
            str = document.getElementById('page2').innerHTML;     //获取需要打印的页面元素
            content = content + str;

            printStr = printStr + content + "</body></html>";
            var pwin = window.open("Print.htm", "print"); //如果是本地测试，需要先新建Print.htm，如果是在域中使用，则不需要
            pwin.document.write(printStr);
            pwin.document.close();                   //这句很重要，没有就无法实现  
            pwin.print();
        }
    </script>
</head>

<body>
    <div><input type="button" value="打印" onclick="Print()" /></div>
    <div id="page1">
        <table width="100%" border="0" cellpadding="0" cellspacing="0" style="page-break-after:always">
            <tr>
                <td>第一页打印内容</td>
            </tr>
        </table>
    </div>
    <div id="page2">
        <table width="100%" border="0" cellpadding="0" cellspacing="0" id="content">
            <tr>
                <td>第二页打印内容</td>
            </tr>
        </table>
    </div>
</body>